#include <iostream>
#include <math.h>
using namespace std;

class Solution
{
public:
    /**
     * @brief The input must be a binary string of length 32
     *
     * @param n
     * @return int
     */
    int hammingWeight(uint32_t n)
    {
        int count = 0;
        while (n)
        {
            if (n % 2 == 1)
            {
                count++;
            }
            n /= 2;
        }
        return count;
    }

    int hammingWeight_2(uint32_t n)
    {
        int res = 0;
        while (n)
        {
            n &= n - 1;
            res++;
        }
        return res;
    }

    int hammingWeight_3(uint32_t n)
    {
        int count = 0;
        if (!n)
        {
            return count;
        }

        while (n)
        {
            int tmp = log2(n);
            count++;
            n -= pow(2, tmp);
        }
        return count;
    }
};

int main(int argc, char const *argv[])
{
    Solution s;
    /**
     * @brief
     * 0b00000000000000000000000000001011 3
     * 0b00000000000000000000000010000000 1
     * 0b11111111111111111111111111111101 31
     */
    cout << s.hammingWeight_3(0b11111111111111111111111111111101) << endl;
    return 0;
}
